home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / chrono / chronog.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  3KB  |  176 lines

  1. unit Chronog;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs;
  8.  
  9. type
  10.   TChrono = class(TComponent)
  11.   private
  12.     { Private-dΘclarations }
  13.     Ftimestart:            TDateTime;
  14.     Ftimestop:             TDateTime;
  15.     FDelay:                TDateTime;
  16.     FDelayInitial:         TDateTime;
  17.     FDelayaver:            TdateTime;
  18.     FDelaytotal:           TDateTime;
  19.     FNumbermes:            Integer;
  20.     Fifpause:              Boolean;
  21.     Fifstart:              Boolean;
  22.   protected
  23.     { Protected-dΘclarations }
  24.     function getlast: Longint;
  25.     function getaver: Longint;
  26.     function gettotal: Longint;
  27.   public
  28.     { Public-dΘclarations }
  29.     constructor Create( Aowner: TComponent ); override;
  30.     destructor Destroy; override;
  31.     procedure start;
  32.     procedure stop;
  33.     procedure pause;
  34.     procedure continue;
  35.     procedure cancel;
  36.     procedure raz;
  37.     property last: Longint read getlast;
  38.     property aver: Longint read getaver;
  39.     property total: Longint read gettotal;
  40.     property nb: Integer read Fnumbermes;
  41.  
  42.   published
  43.     { Published-dΘclarations }
  44.   end;
  45.  
  46. procedure Register;
  47.  
  48. implementation
  49.  
  50. procedure Register;
  51. begin
  52.   RegisterComponents('Comp.', [TChrono]);
  53. end;
  54.  
  55. constructor TChrono.create( Aowner: Tcomponent);
  56. begin
  57.   inherited Create( Aowner );
  58.   Fifpause:= False;
  59.   Fifstart:= False;
  60.   FDelay:=0;
  61.   FDelayInitial:=0;
  62.   FDelayaver:=0;
  63.   FDelaytotal:=0;
  64.   FNumbermes:=0;
  65. end;
  66.  
  67. destructor TChrono.destroy;
  68. begin
  69.   inherited Destroy;
  70. end;
  71.  
  72. procedure TChrono.start;
  73. begin
  74. if Fifpause=false then
  75.  begin
  76.   if Fifstart=False then
  77.    begin
  78.         Fifstart:=true;
  79.         Fifpause:=false;
  80.         FTimestart:=Time;
  81.         Fnumbermes:=Fnumbermes+1;
  82. {        Fdelaytotal:=0;}
  83.         Fdelayinitial:=0;
  84.    end;
  85.  end;
  86. end;
  87.  
  88. procedure TChrono.stop;
  89. begin
  90. if Fifpause=false then
  91. begin
  92.  if Fifstart then
  93.   begin
  94.        Fifstart:=false;
  95.        FTimestop:=Time;
  96.        if FTimestop <= Ftimestart then Ftimestop:=Ftimestop+1;
  97.        Fdelay:=FTimestop-FTimestart+Fdelayinitial;
  98.        Fdelaytotal:=Fdelaytotal+Fdelay;
  99.        Fdelayaver:=Fdelaytotal/Fnumbermes;
  100.   end;
  101.  end else
  102.  begin
  103.        Fifstart:=false;
  104.        Fifpause:=false;
  105.        Fdelaytotal:=Fdelaytotal+Fdelay;
  106.        Fdelayaver:=Fdelaytotal/Fnumbermes;
  107.  end;
  108. end;
  109.  
  110. procedure Tchrono.cancel;
  111. begin
  112. if Fifstart then
  113.  begin
  114.  Fifstart:=false;
  115.  Fifpause:=false;
  116.  Fnumbermes:=Fnumbermes - 1;
  117.  Fdelay:=0;
  118.  end;
  119. end;
  120.  
  121. procedure TChrono.pause;
  122. begin
  123. if Fifpause=false then
  124. begin
  125.  if Fifstart then
  126.   begin
  127.        FTimestop:=Time;
  128.        Fifpause:=true;
  129.        if FTimestop <= Ftimestart then Ftimestop:=Ftimestop+1;
  130.        Fdelay:=FTimestop-FTimestart+Fdelayinitial;
  131.  {      Fdelayinitial:=Fdelay}
  132.   end;
  133.  end;
  134. end;
  135.  
  136. procedure TChrono.continue;
  137. begin
  138. if Fifpause then
  139. begin
  140.  if Fifstart then
  141.   begin
  142.   Fifpause:=false;
  143.   Fdelayinitial:=Fdelay;
  144.   Ftimestart:=Time;
  145.   end;
  146.  end;
  147. end;
  148.  
  149. procedure TChrono.raz;
  150. begin
  151.   Fifpause:= False;
  152.   Fifstart:= False;
  153.   FDelay:=0;
  154.   FDelayInitial:=0;
  155.   FDelayaver:=0;
  156.   FDelaytotal:=0;
  157.   FNumbermes:=0;
  158. end;
  159.  
  160. function Tchrono.getlast;
  161. begin
  162. Result:=round(FDelay*24*3600*1000);
  163. end;
  164.  
  165. function Tchrono.getaver;
  166. begin
  167. Result:=round(FDelayaver*24*3600*1000);
  168. end;
  169.  
  170. function Tchrono.gettotal;
  171. begin
  172. result:=round(Fdelaytotal*24*3600*1000);
  173. end;
  174.  
  175. end.
  176.